package com.example.esdemo.configure;

import com.example.esdemo.constants.RabbitConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq 配置
 *
 * @author Cary
 * @date 2022/6/21
 */
@Configuration
public class RabbitMqConfig {

    @Bean
    public Queue esQueue() {
        return new Queue(RabbitConstant.ES_QUEUE);
    }

    @Bean
    public DirectExchange esExchange() {
        return new DirectExchange(RabbitConstant.ES_EXCHAGE);
    }

    /**
     * 交换机和队列进行绑定
     *
     * @param esExchange
     * @param esQueue
     * @return
     */
    @Bean
    public Binding bindingDirect(DirectExchange esExchange, Queue esQueue) {
        return BindingBuilder.bind(esQueue).to(esExchange).with(RabbitConstant.ES_ROUTING_KEY);
    }
}
